import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { CreateOrderDto } from './dto/create-order.dto';
import { OrderService } from './order.service';

@Controller('order')
export class OrderController {
  constructor(private readonly orderService: OrderService) {}
  //创建
  @Post()
  create(@Body() createOrderDto: CreateOrderDto) {
    return this.orderService.create(createOrderDto);
  }

  @Post('unpay')
  createUnpay(@Body() createOrderDto: CreateOrderDto) {
    return this.orderService.createUnpay(createOrderDto);
  }

  //查询所有有效订单
  @Get('useful/:id')
  findByStatus(@Param('id', ParseIntPipe) userId: number) {
    return this.orderService.findUserful(userId);
  }
  //查询所有待支付订单
  @Get('unpay/:id')
  findUnpay(@Param('id', ParseIntPipe) userId: number) {
    return this.orderService.findUnpay(userId);
  }
  //查询当日所有订单
  @Get('day')
  findDay() {
    return this.orderService.findDay();
  }

  @Get('this')
  findThisWeek() {
    return this.orderService.findThisWeek();
  }

  @Get('last')
  findLastWeek() {
    return this.orderService.findLastWeek();
  }

  @Get()
  findAll(){
    return this.orderService.findAll()
  }
  //分页查询订单
  @Get('page')
  findByPage(
    @Query('page', ParseIntPipe) page: number,
    @Query('take', ParseIntPipe) take: number,
  ) {
    let skip = (page - 1) * take;
    return this.orderService.findByPage(skip, take);
  }
  // 查询订单条数
  @Get('count')
  findCount() {
    return this.orderService.findCount();
  }

  @Get(':id')
  findByUser(@Param('id', ParseIntPipe) userId: number) {
    return this.orderService.findByUser(userId);
  }
  //更新订单
  @Patch(':id')
  update(
    @Param('id', ParseIntPipe) id: number,
    @Body('status') status: number,
  ) {
    return this.orderService.update(id, status);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.orderService.remove(+id);
  }
}
